package logic

import (
	"core/command"
	"core/component/logger"
)

// 开始匹配
func (player *Player) startPvpHandler(msgID uint16, data []byte) {
	msgRecv := &command.CSStartPvp{}
	err := player.router.UnMarshal(data, msgRecv)
	if err != nil {
		logger.Errorf("recv data:%v msg:%v", data, msgRecv)
		return
	}
	if player.isGaming {
		logger.Errorf("玩家正在游戏中 playerID:%v", player.playerId)
		return
	}
	player.isGaming = true
	WorldGetMe().pvps.addToPool(LowScore, player)
	logger.Infof("[玩家进入匹配池] playerId:%v nickName:%v score:%v", player.playerId, player.nickName, player.score)
}

func (player *Player) cancelPvpHandler(msgID uint16, data []byte) {
	msgRecv := &command.SCCancelPvp{}
	err := player.router.UnMarshal(data, msgRecv)
	if err != nil {
		logger.Errorf("recv data:%v msg:%v", data, msgRecv)
		return
	}
	if !player.isGaming {
		logger.Errorf("玩家不在游戏中 playerID:%v", player.playerId)
		return
	}
	player.cancelPvp()
}

//func (player *Player) outOfCardHandler(msgID uint16, data []byte) {
//	msgRecv := &command.CSOutOfCardsPvp{}
//	err := player.router.UnMarshal(data, msgRecv)
//	if err != nil {
//		logger.Errorf("recv data:%v msg:%v", data, msgRecv)
//		return
//	}
//	player.outOfCard(msgRecv.RoomId, msgRecv.Cards)
//}

//func (player *Player) playerExitPvpHandler(msgID uint16, data []byte) {
//	msgRecv := &command.CSPlayerExitPvp{}
//	err := player.router.UnMarshal(data, msgRecv)
//	if err != nil {
//		logger.Errorf("recv data:%v msg:%v", data, msgRecv)
//		return
//	}
//	player.closeChannel <- 0
//}
